package org.ewaf.framework.model;

import org.apache.commons.beanutils.BeanUtils;


public abstract class BaseDataObject implements IDataObject {

	private static final long serialVersionUID = 1L;

	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (! (obj instanceof BaseDataObject)) {
			return false;
		}
		
		Object id1 = getId();
		Object id2 = ((BaseDataObject) obj).getId();
		if (id1 != null && id2 != null) {
			return id1.equals(id2);
		} else {
			return this == obj;
		}
	}
	
	public int hashCode() {
		Object id = getId();
		return id == null ? super.hashCode() : id.hashCode();
	}
	
	public String toString() {
		try {
			return BeanUtils.describe(this).toString();
		} catch (Exception e) {
			return super.toString();
		}
	}
	
	
}
